<template>
  <div>
     <van-nav-bar title="修改个人信息" left-arrow @click-left="goBack()"></van-nav-bar>
    <div class="changePwd">
      <van-field label="账号" disabled="" v-model="userInfo.id" required></van-field>
      <van-field label="用户名" v-model="userInfo.username" required></van-field>
      <van-field v-model="userInfo.address" label="地址" required></van-field>
      <van-field v-model="userInfo.phone" label="手机号码" required></van-field>


      <div class="btn">
        <van-button type="default" size="large" color="#62cff9" @click="save(item)">保存</van-button>
      </div>
    </div>
  </div>
</template>

<script>
  import {
    Toast
  } from 'vant'
  export default {
    data() {
      return {
        userInfo: [],

        dep: '',
        role: ''

      };
    },
    created() {
      this.getUser();
    },
    methods: {
      save(item) {
        this.$axios.post('Magment/updateUser.do', {
          address: this.userInfo.address,
          depid: this.userInfo.depid,
          id: this.userInfo.id,
          username: this.userInfo.username,
          phone: this.userInfo.phone,
          role: this.userInfo.role
        }).then(res => {
          if (res.data.status === 200) {
            Toast.success('修改成功！')
            this.getUser()
          }
        })
      },
      getUser() {
        let id = JSON.parse(localStorage.cksLoginInfo).id
        console.log(id)
        this.$axios.post("/Magment/QueryMangment.do",{id:id,username:""}).then(res => {
          this.userInfo = res.data.msg[0]
        }).catch(err=>{
          Toast.fail({message:'系统异常',duration:900})
        })
      }
    }
  };
</script>


<style scoped="scoped">
  .van-button--large {
    height: 2.3rem;
    line-height: 2.3rem;
    margin-bottom: 0.7rem;
  }

  .btn {
    padding: 0.8rem;
    border-radius: 15px;
  }
</style>
